﻿package mortal.game.view.combinedServer
{
    import Message.Game.*;
    import mortal.common.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.view.ThanksGiving.data.*;
    import mortal.game.view.combinedServer.combinedSerDayRe1000.*;
    import mortal.game.view.combinedServer.data.*;
    import mortal.game.view.combinedServer.item.*;
    import mortal.game.view.copy.*;
    import mortal.game.view.copy.QuestionCopy.data.*;
    import mortal.mvc.interfaces.*;

    public class CombinedSerController extends CopyControllerBase
    {
        private var _addEnd:Boolean = false;

        public function CombinedSerController()
        {
            return;
        }// end function

        override protected function initServer() : void
        {
            EventUtil.addNetEvent(ServerCommand.CombinedSerOpenInfo, this.onOpenActive, true);
            EventUtil.addSelfEvent(CombinedSerEvent.CombinedSerOpenMode, this.onOpenModuel, true);
            EventUtil.addNetEvent(ServerCommand.CombinedSerRechargeInfo, this.onRechargeInfoBack, true);
            EventUtil.addNetEvent(ServerCommand.RebateDayChargeInfoBack, this.onRechargeInfoBack, true);
            EventUtil.addSelfEvent(CombinedSerEvent.CombinedSerRechargeGetRw, this.onGetRechargeRw, true);
            EventUtil.addSelfEvent(CombinedSerEvent.CombinedSerReqRankInfo, this.onReqRankInfo, true);
            EventUtil.addNetEvent(ServerCommand.CombinedSerRankInfo, this.onRankBack, true);
            EventUtil.addNetEvent(ServerCommand.CombinedSerRecharge1000Info, this.onRecharge1000InfoBack, true);
            EventUtil.addSelfEvent(ThanksGivingEvent.CombinedSerRe1000GetRw, this.onGet500RwHd, true);
            EventUtil.addNetEvent(ServerCommand.RebateDayChargeInfoBack, this.onRechargeNumChange, true);
            EventUtil.addNetEvent(ServerCommand.CombinedSerRankInfo, this.onRe1000RankBack, true);
            LevelCheckUtil.addInit(this.initHd);
            EventUtil.addNetEvent(ServerCommand.NewDayUpdate, this.updateZero, true);
            return;
        }// end function

        override public function get view() : IView
        {
            if (_view == null)
            {
                _view = new CombinedSerModule();
            }
            return _view;
        }// end function

        private function onOpenActive(param1:Object) : void
        {
            this.initHd(null);
            return;
        }// end function

        private function initHd(param1:Object) : void
        {
            var _loc_2:Date = null;
            var _loc_3:Date = null;
            if (CombinedSerUtil.canShowIcon())
            {
                CombinedSerActIcon.instance.show();
                CombinedSerDayRe1000Icon.instance.show();
                this.check1000RwIcon();
                _loc_2 = CombinedSerUtil.getStarDt();
                if (_loc_2 != null)
                {
                    if (this._addEnd == false)
                    {
                        this._addEnd = true;
                        _loc_3 = CombinedSerUtil.getEndDt();
                        ClockManager.instance.addDateCall(_loc_3, this.onActionEnd);
                    }
                }
            }
            else if (CombinedSerActIcon.hasInstance() && CombinedSerActIcon.instance.isHide == false)
            {
                CombinedSerActIcon.instance.hide();
            }
            this.checkHasReward();
            return;
        }// end function

        private function onActionEnd() : void
        {
            this._addEnd = false;
            if (CombinedSerActIcon.hasInstance() && CombinedSerActIcon.instance.isHide == false)
            {
                CombinedSerActIcon.instance.hide();
            }
            if (CombinedSerDayRe1000Icon.hasInstance() && CombinedSerDayRe1000Icon.instance.isHide == false)
            {
                CombinedSerDayRe1000Icon.instance.hide();
            }
            if (_view && _view.hide() == false)
            {
                this.view.hide();
            }
            if (CombinedSerDayRe1000Module.isView && CombinedSerDayRe1000Module.instance.isHide == false)
            {
                CombinedSerDayRe1000Module.instance.hide();
            }
            return;
        }// end function

        private function updateZero(param1:Object) : void
        {
            var _loc_2:* = ClockManager.instance.getDelayDate(1000);
            ClockManager.instance.addDateCall(_loc_2, this.refleshDate);
            return;
        }// end function

        private function refleshDate() : void
        {
            this.initHd(null);
            this.onRechargeInfoBack(null);
            this.onRankBack(null);
            return;
        }// end function

        private function onOpenModuel(event:DataEvent) : void
        {
            this.view.show();
            return;
        }// end function

        private function onRechargeInfoBack(param1:Object) : void
        {
            if (_view && _view.isHide == false)
            {
                (_view as CombinedSerModule).updateRecharge();
            }
            this.checkHasReward();
            return;
        }// end function

        private function onGetRechargeRw(event:DataEvent) : void
        {
            var _loc_2:* = event.data as int;
            GameProxy.role.getMegerRechargeActiveReward(_loc_2);
            this.checkHasReward();
            return;
        }// end function

        private function checkHasReward() : void
        {
            return;
        }// end function

        private function onReqRankInfo(event:DataEvent) : void
        {
            GameProxy.role.getMegerRechargeTopList();
            return;
        }// end function

        private function onRankBack(param1:Object) : void
        {
            if (_view && _view.isHide == false)
            {
                (_view as CombinedSerModule).updateRank();
            }
            return;
        }// end function

        private function onRecharge1000InfoBack(param1:Object) : void
        {
            if (CombinedSerDayRe1000Module.isView)
            {
                CombinedSerDayRe1000Module.instance.updateRecharge();
            }
            this.check1000RwIcon();
            return;
        }// end function

        private function onGet500RwHd(event:DataEvent) : void
        {
            GameProxy.role.getMegerRechargeReturnCash();
            return;
        }// end function

        private function check1000RwIcon() : void
        {
            if (CombinedSerDayRe1000Util.getRwIndex() > -1)
            {
                if (CombinedSerDayRe1000Icon.hasInstance())
                {
                    CombinedSerDayRe1000Icon.instance.playEffect();
                }
            }
            else if (CombinedSerDayRe1000Icon.hasInstance())
            {
                CombinedSerDayRe1000Icon.instance.stopEffect();
            }
            return;
        }// end function

        private function onRe1000RankBack(param1:Object) : void
        {
            if (CombinedSerDayRe1000Module.isView)
            {
                CombinedSerDayRe1000Module.instance.updateRank();
            }
            return;
        }// end function

        private function onRechargeNumChange(param1:Object) : void
        {
            var _loc_2:* = Cache.instance.combinedSer.recharge1000Info;
            if (_loc_2)
            {
                _loc_2.recharge = Cache.instance.rebate.rechargeSum;
                this.onRecharge1000InfoBack(null);
            }
            return;
        }// end function

    }
}
